<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      lang="en-us"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->

    <title> 新闻后台管理 </title>
    <meta name="description" content=""/>
    <meta name="author" content=""/>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/bootstrap.min.css" th:href="@{/resources/css/bootstrap.min.css}" />
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/font-awesome.min.css" th:href="@{/resources/css/font-awesome.min.css}"/>

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-production-plugins.min.css" th:href="@{/resources/css/smartadmin-production-plugins.min.css}"/>
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-production.min.css" th:href="@{/resources/css/smartadmin-production.min.css}"/>
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-skins.min.css" th:href="@{/resources/css/smartadmin-skins.min.css}"/>

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-rtl.min.css" th:href="@{/resources/css/smartadmin-rtl.min.css}"/>

    <!-- FAVICONS -->
    <link rel="shortcut icon" href="../../static/img/favicon/favicon.ico" type="image/x-icon" th:href="@{/resources/img/favicon/favicon.ico}"/>
    <link rel="icon" href="../../static/img/favicon/favicon.ico" type="image/x-icon" th:href="@{/resources/img/favicon/favicon.ico}"/>

</head>

<body class="">

<!-- HEADER -->
<header id="header">
    <div id="logo-group">

        <!-- PLACE YOUR LOGO HERE -->
        <span id="logo"><a th:href="@{/}"> <img th:src="@{/resources/img/logo.png}" alt="logo" /></a></span>
        <!-- END LOGO PLACEHOLDER -->

    </div>

    <!-- pulled right: nav area -->
    <div class="pull-right">

        <!-- collapse menu button -->
        <div id="hide-menu" class="btn-header pull-right">
            <span> <a href="javascript:void(0);" data-action="toggleMenu" title="Collapse Menu"><i class="fa fa-reorder">隐藏</i></a> </span>
        </div>
        <!-- end collapse menu -->

        <!-- logout button -->
        <div id="logout" class="btn-header transparent pull-right">
            <span> <a th:href="@{/logout}" title="登出" data-action="userLogout" data-logout-msg="您确定要退出登录吗?"><i class="fa fa-sign-out">退出</i></a> </span>
        </div>
        <!-- end logout button -->

        <!-- fullscreen button -->
        <div id="fullscreen" class="btn-header transparent pull-right">
            <span> <a href="javascript:void(0);" data-action="launchFullscreen" title="全屏"><i class="fa fa-arrows-alt">全屏</i></a> </span>
        </div>
        <!-- end fullscreen button -->
        <!-- home button -->
        <div id="home" class="btn-header transparent pull-right">
            <span> <a th:href="@{/}" title="回到首页"><i class="fa fa-home">首页</i></a> </span>
        </div>
        <!-- end home button -->

    </div>
    <!-- end pulled right: nav area -->

</header>
<!-- END HEADER -->

<!-- Left panel : Navigation area -->
<aside id="left-panel">
    <nav>
        <ul>
            <li th:each="channel : ${channels}" th:classappend="${ch.channel_id==channel.channel_id}?'active':''"
                th:value="${channel.channel_id}">
                <a href="javascript:">
                    <i class="fa fa-lg fa-book"></i>
                    <span class="menu-item-parent fa-lg" th:text="${channel.title}">频道</span>
                </a>
                <ul th:with="columns=${channel.columns}">
                    <!--<li class="columnLi"-->
                        <!--th:classappend="${channel.channel_id==ch.channel_id}?'active':''"-->
                        <!--th:attrappend="-->
                            <!--data-channel-id=${channel.channel_id},-->
                            <!--data-column-id=0,-->
                            <!--data-column-url=@{/channel/setting}">-->
                        <!--<a href="javascript:">-->
                            <!--<i class="fa fa-lg fa-edit"></i>-->
                            <!--<span class="menu-item-parent fa-lg">设置</span>-->
                        <!--</a>-->
                    <!--</li>-->
                    <li th:each="tempCol : ${channel.columns}"
                    th:classappend="${tempCol.column_id==column.column_id}?'active':''"
                    class="columnLi"
                    th:attrappend="
                    data-channel-id=${channel.channel_id},
                    data-column-id=${tempCol.column_id},
                    data-column-url=@{/column/setting}">
                    <a href="javascript:">
                    <i class="fa fa-lg fa-edit"></i>
                    <span class="menu-item-parent fa-lg" th:text="${tempCol.title}">栏目</span>
                    </a>
                    </li>
                </ul>
            </li>
        </ul>
    </nav>
</aside>
<!-- END NAVIGATION -->
<!-- MAIN PANEL -->
<div id="main" role="main">

    <!-- RIBBON -->
    <div id="ribbon">

        <!-- breadcrumb -->
        <ol class="breadcrumb">
            <i class="fa fa-arrow-right"></i>
            <li class="fa fa-lg" th:text="'编辑栏目 - '+${column.title}"></li>
        </ol>

    </div>
    <!-- END RIBBON -->

    <!-- MAIN CONTENT -->
    <div id="content">

        <!-- widget grid -->
        <section id="widget-grid" class="">

            <!-- row -->
            <div class="row">

                <article class="col-xs-12 col-sm-12">

                    <!-- Widget ID (each widget will need unique ID)-->
                    <div class="jarviswidget jarviswidget-color-green" id="wid-id-0" data-widget-colorbutton="false" data-widget-editbutton="false" data-widget-deletebutton="false" data-widget-custombutton="false">

                        <header>
                            <span class="widget-icon"> <i class="fa fa-info-circle"></i></span>
                            <h2>编辑栏目</h2>

                        </header>

                        <!-- widget div-->
                        <div>

                            <!-- widget content -->
                            <div class="widget-body no-padding">

                                <form class="smart-form " id="editForm">
                                    <header>
                                        栏目信息
                                    </header>

                                    <fieldset>
                                        <div class="row">
                                            <section class="col col-4">
                                                <label class="label font-lg">栏目名称：</label>
                                                <input class="font-md" id="title" th:value="${column.title}" name="title"/>
                                            </section>
                                            <section class="col col-4">
                                                <label class="select font-lg">栏目类型：</label>
                                                <select class=" font-md" id="type" th:value="${column.type}" name="type">
                                                    <option value="10">普通栏目</option>
                                                </select>
                                            </section>
                                            <section class="col col-4">
                                                <label class="label font-lg">频道：</label>
                                                <input class=" font-md" th:value="${ch.title}" data-th-readonly="true" id="channel_title"/>
                                                <div class="note">
                                                    <strong>提示:</strong>请谨慎修改
                                                </div>
                                            </section>
                                        </div>
                                    </fieldset>
                                    <footer>
                                        <!-- 保存按钮 -->
                                        <button type="button" id="save_btn" href="javascript:" class="btn btn-primary">
                                            <i class="fa fa-save"></i>
                                            保存
                                        </button>
                                        <!-- 返回按钮 -->
                                        <button type="button" onclick="javascript:history.back();" class="back_btn btn btn-danger">
                                            <i class="fa fa-backward"></i>
                                            返回
                                        </button>
                                        <!-- 更改频道按钮 -->
                                        <button type="button"  href="javascript:" data-toggle="modal" data-target="#channelModal" class="back_btn btn btn-warning">
                                            <i class="fa fa-edit"></i>
                                            更改频道
                                        </button>
                                    </footer>

                                </form>

                            </div>
                            <!-- end widget content -->

                        </div>
                        <!-- end widget div -->

                    </div>
                    <!-- end widget -->

                </article>

            </div>

            <!-- row -->
            <div class="row">

                <article class="col-xs-12 col-sm-12">

                    <!-- Widget ID (each widget will need unique ID)-->
                    <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1" data-widget-colorbutton="false"
                         data-widget-deletebutton="false" data-widget-editbutton="false">
                        <header>
                            <span class="widget-icon"> <i class="fa fa-table"></i> </span>

                            <h2>新闻列表</h2>

                        </header>

                        <!-- widget div-->
                        <div>
                            <!-- widget content -->
                            <div class="widget-body">

                                <form class="smart-form">

                                    <header>近期新增</header>

                                    <fieldset>
                                        <div class="table-responsive">
                                            <table class="table table-bordered ">
                                                <thead>
                                                <tr>
                                                    <th style="text-align:center;width:4%"><input type="checkbox"
                                                                                                  id="check_all"
                                                                                                  onclick="checkAllRows()"
                                                                                                  title="全选"/></th>
                                                    <th>新闻编号</th>
                                                    <th>新闻标题</th>
                                                    <th>来源</th>
                                                    <th>创建日期</th>
                                                    <th>操作</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr th:each="article : ${column.articles}" th:id="'news'+${article.article_id}">
                                                    <th style="text-align: center;width:4%;">
                                                        <input type="checkbox" name="check_single_row"
                                                               onclick="cancelCheckAllStatus()"
                                                               th:value="${article.article_id}"/>
                                                    </th>
                                                    <td th:text="${article.article_id}"></td>
                                                    <td th:text="${article.title}"></td>
                                                    <td th:text="${article.source}"></td>
                                                    <td th:text="${article.dateTimeStr}"></td>
                                                    <td>
                                                        <label class="fa fa-edit edit-news-btn"
                                                               th:attr="data-news-id=${article.article_id}">编辑</label>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>

                                    </fieldset>

                                    <footer>
                                        <!-- 添加按钮 -->
                                        <button type="button" href="javascript:" id="addNewsBtn" class="btn btn-info">
                                            <i class="fa fa-plus"></i>
                                            新增
                                        </button>
                                        <button type="button" id="delete_btn"
                                                href="javascript:" class="btn btn-danger">
                                            <i class="fa fa-trash-o"></i>
                                            删除
                                        </button>
                                        <!-- 刷新按钮 -->
                                        <button type="button" id="refresh_btn"
                                                href="javascript:" class="btn btn-success">
                                            <i class="fa fa-refresh"></i>
                                            刷新
                                        </button>
                                        <!-- 刷新按钮 -->
                                        <button type="button" id="show_all_news"
                                                href="javascript:" class="btn btn-primary">
                                            <i class="fa fa-truck"></i>
                                            查看全部
                                        </button>

                                    </footer>

                                </form>


                            </div>
                            <!-- end widget content -->

                        </div>
                        <!-- end widget div -->

                    </div>
                    <!-- end widget -->

                </article>

            </div>

            <!-- end row -->

        </section>
        <!-- end widget grid -->

        <!-- Modal -->
        <div class="modal fade" id="channelModal" tabindex="-1" role="dialog" aria-labelledby="channelModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="channelModalLabel"><i class="fa fa-edit"></i>更换频道</h4>
                    </div>

                    <div class="modal-body">
                        <div class="row">
                            <div class="col col-sm-12 col-md-8 col-lg-4 alert alert-info fade in">
                                <i class="fa-fw fa fa-info"></i>
                                <strong>提醒！</strong> 选择一个频道
                            </div>
                            <div class="col-md-12 col-lg-8 col-lg-offset-2">
                                <form class="smart-form">
                                    <header>
                                        频道列表
                                    </header>
                                    <fieldset>
                                        <div class="row">
                                            <section>
                                                <label class="select">
                                                    <select class="input-lg" id="select_channel">
                                                        <option th:each="channel : ${channels}" th:value="${channel.channel_id}" th:text="${channel.title}">频道名称</option>
                                                    </select><i></i>
                                                </label>
                                            </section>
                                        </div>
                                    </fieldset>

                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Cancel
                        </button>
                        <button type="button" class="btn btn-primary" id="channel_save_btn">
                            保存
                        </button>

                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->



    </div>
    <!-- END MAIN CONTENT -->

</div>
<!-- END MAIN PANEL -->

<!-- PAGE FOOTER -->
<div class="page-footer">
    <div class="row">
        <div class="col-xs-12 col-sm-6">
            <span class="txt-color-white">新闻后台管理</span>
        </div>

    </div>
</div>
<!-- END PAGE FOOTER -->


<!--================================================== -->

<script src="../../static/js/libs/jquery-2.1.1.min.js" th:src="@{/resources/js/libs/jquery-2.1.1.min.js}"></script>

<script src="../../static/js/libs/jquery-ui-1.10.3.min.js" th:src="@{/resources/js/libs/jquery-ui-1.10.3.min.js}"></script>

<!-- IMPORTANT: APP CONFIG -->
<script src="../../static/js/app.config.js" th:src="@{/resources/js/app.config.js}"></script>

<!-- BOOTSTRAP JS -->
<script src="../../static/js/bootstrap/bootstrap.min.js" th:src="@{/resources/js/bootstrap/bootstrap.min.js}"></script>

<!-- JARVIS WIDGETS -->
<script src="../../static/js/smartwidgets/jarvis.widget.min.js" th:src="@{/resources/js/smartwidgets/jarvis.widget.min.js}"></script>

<!-- JQUERY VALIDATE -->
<script src="../../static/js/plugin/jquery-validate/jquery.validate.min.js" th:src="@{/resources/js/plugin/jquery-validate/jquery.validate.min.js}"></script>

<!-- JQUERY MASKED INPUT -->
<script src="../../static/js/plugin/masked-input/jquery.maskedinput.min.js" th:src="@{/resources/js/plugin/masked-input/jquery.maskedinput.min.js}"></script>

<!-- JQUERY SELECT2 INPUT -->
<script src="../../static/js/plugin/select2/select2.min.js" th:src="@{/resources/js/plugin/select2/select2.min.js}"></script>

<!--[if IE 8]>

<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>

<![endif]-->

<!-- MAIN APP JS FILE -->
<script src="../../static/js/app.min.js" th:src="@{/resources/js/app.min.js}"></script>
<script src="../../static/js/plugin/jquery-nestable/jquery.nestable.min.js" th:src="@{/resources/js/plugin/jquery-nestable/jquery.nestable.min.js}"></script>

<script src="../../static/js/plugin/ckeditor/ckeditor.js" th:src="@{/resources/js/plugin/ckeditor/ckeditor.js}"></script>

<!-- PAGE RELATED PLUGIN(S) -->
<script th:inline="javascript">
    /*<![CDATA[*/

    $channel_id = 0;
    var column_id;
    /*[+
     $channel_id = [[${ch.channel_id}]];
     column_id = [[${column.column_id}]];
     +]*/

    // DO NOT REMOVE : GLOBAL FUNCTIONS!
    $(document).ready(function() {

        pageSetUp();

//        localStorage.clear();

        $('#select_channel').val($channel_id);

        $('#show_all_news').click(function () {
            var url = "";
            /*[+
                url = [[@{/article/list}]];
            +]*/
            location.href=url+"?column_id="+column_id;
        })

        $(".columnLi").click(function () {
            var column_id = $(this).data("column-id");
            var channel_id = $(this).data("channel-id");
            var url = $(this).data("column-url");
            window.location.href = url + "?channel_id=" + channel_id + "&column_id=" + column_id;
        });

        $("#save_btn").click(function () {

            var formData = new FormData(document.getElementById("editForm"));
            var url;

            /*[+
                url = [[@{/column/save}]];
             +]*/

            formData.append("channel_id",$channel_id);
            formData.append("column_id",column_id);

            $.ajax({
                url:url,
                contentType:false,
                processData:false,
                data:formData,
                type:"POST",
                success: function (data) {
                    alert("保存成功!");
                    location.reload();
                    return false;
                },
                error: function () {
                    alert("保存失败!");
                    return false;
                }

            });
        })

        $('#channel_save_btn').click(function () {
            var channel_id = $('#select_channel').val();
            var url = /*[[@{/column/channel/update}]]*/"";
            $.post(url,{column_id:column_id,channel_id:channel_id}, function (data) {
                location.reload();
            });
        });

        $('#addNewsBtn').click(function () {
            var url = "";
            /*[+
                url = [[@{/article/append}]];
            +]*/
            location.href=url+"?column_id="+column_id;
        })

        $("#delete_btn").click(function () {
            var url = /*[[@{/article/delete}]]*/"";
            var checked_ids = "";
            $("[name='check_single_row']:checked").each(function () {
                checked_ids += "," + $(this).val();
            });

            if (checked_ids.length == 0) {
                alert("您还没有选中要删除的项目");
                return;
            } else {
                checked_ids = checked_ids.substring(1);
            }

            var result = window.confirm("确认删除选中的项目?");
            if (result == false) {
                return;
            }

            $.post(url, {deleteIds: checked_ids}, function (data) {
                if (data.code == 1) {
                    location.reload();
//                    var ids = data.ids;
//                    for (var i in ids) {
//                        $("#col" + ids[i]).remove();
//                    }
                }
            }); // end post
        }); // end click func

        $("#refresh_btn").click(function () {

            location.reload();
        }); // end click func



    });

    function checkAllRows() {
        var if_checked = document.getElementById("check_all").checked;
        var boxs = document.getElementsByName("check_single_row");
        for (var i = 0; i < boxs.length; i++) {
            boxs[i].checked = if_checked;
        }
    }

    function cancelCheckAllStatus() {

        var boxs = document.getElementsByName("check_single_row");
        var flag = true;
        for (var i = 0; i < boxs.length; i++) {
            if (boxs[i].checked == false) {
                flag = false;
                break;
            }
        }
        document.getElementById("check_all").checked = flag;
    }





    /*]]>*/

</script>


</body>

</html>